package com.lin.boot.utils;

import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.IdentifierGenerator;
import org.springframework.util.IdGenerator;

import java.io.Serializable;

public class SnowflakeId implements IdentifierGenerator {

    private SnowflakeIdWorker idWorker = new SnowflakeIdWorker(0, 0);

    @Override
    public Serializable generate(SharedSessionContractImplementor session, Object object) throws HibernateException {
        return String.valueOf(idWorker.nextId());
    }

    @Override
    public boolean supportsJdbcBatchInserts() {
        return false;
    }
}
